package com.zte.claa.inficombo.csa.app.service.rptparse.ext.gnss.mina;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zte.claa.inficombo.csa.app.service.rptparse.ext.gnss.IGnssParseResultReceiver;

/**
 * 
 * @项目名称 GnssParseResultIoHandler
 * 
 * @类名 GnssParseResultIoHandler
 * 
 * @类描 异步消息处理
 * 
 * @创建时间 2018-8-18
 * 
 */
public class GnssParseResultIoHandler extends IoHandlerAdapter {
	// 日志记录》
	private static final Logger LOG = LoggerFactory.getLogger(GnssParseResultIoHandler.class);
	// 消息接收处理器.
	private IGnssParseResultReceiver resultReceiver;

	@Override
	public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
		LOG.error("消息接收异常，客户端IP:" + session.getRemoteAddress(), cause);
	}
	
	// 构建器.
	public GnssParseResultIoHandler(IGnssParseResultReceiver resultReceiver){
		super();
		this.resultReceiver = resultReceiver;
	}

	@Override
	public void messageReceived(IoSession session, Object message) throws Exception {
		LOG.info("Receive message: "+message);
		if(this.resultReceiver == null){
			LOG.error("resultReceiver is null, maybe not init correctly!");
			return;
		}
		this.resultReceiver.onParseResultReceive(message);
	}

}
